# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Maintainer: Ray Donnelly <mingw.android@gmail.com>
# Contributor: Saul Ibarra Corretge <saghul@gmail.com>
# Contributor: Frode Solheim <frode@fs-uae.net>

_primary_python="yes"
_pybasever=3.11
_realname=python

if [[ "${_primary_python}" == "yes" ]]; then
  pkgbase="mingw-w64-${_realname}"
  pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
  provides=("${MINGW_PACKAGE_PREFIX}-python3"
            "${MINGW_PACKAGE_PREFIX}-python${_pybasever}")
  conflicts=("${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python${_pybasever}"
            "${MINGW_PACKAGE_PREFIX}-python2<2.7.16-7")
  replaces=("${MINGW_PACKAGE_PREFIX}-python3"
            "${MINGW_PACKAGE_PREFIX}-python${_pybasever}")
else
  pkgbase="mingw-w64-${_realname}${_pybasever}"
  pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}${_pybasever}")
fi
pkgver=${_pybasever}.5
pkgrel=2
pkgdesc="A high-level scripting language (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('PSF')
url="https://www.python.org/"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-bzip2"
         "${MINGW_PACKAGE_PREFIX}-libffi"
         "${MINGW_PACKAGE_PREFIX}-mpdecimal"
         "${MINGW_PACKAGE_PREFIX}-ncurses"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-sqlite3"
         "${MINGW_PACKAGE_PREFIX}-tcl"
         "${MINGW_PACKAGE_PREFIX}-tk"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-xz"
         "${MINGW_PACKAGE_PREFIX}-tzdata")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "autoconf-archive"
)
options=('makeflags') # 'debug' '!strip')
source=("https://www.python.org/ftp/python/${pkgver%rc?}/Python-${pkgver}.tar.xz"
        0001-sysconfig-make-_sysconfigdata.py-relocatable.patch
        0002-build-add-with-nt-threads-and-make-it-default-on-min.patch
        0003-Define-MS_WINDOWS-and-others-when-compiling-with-MIN.patch
        0004-configure-add-MACHDEP-and-platform-on-MINGW.patch
        0005-Add-default-configuration-for-MINGW.patch
        0006-configure-enable-largefile-support-by-default-for-Mi.patch
        0007-Add-PC-to-CPPFLAGS-and-to-SRCDIRS-on-Mingw.patch
        0008-posixmodule.c-Define-necessary-headers-for-compiling.patch
        0009-Build-winreg-by-default-when-compiling-for-MINGW.patch
        0010-pyport.h-Add-support-for-MINGW.patch
        0011-configure-add-options-so-that-shared-build-is-possib.patch
        0012-Add-dynamic-loading-support-for-MINGW.patch
        0013-Ignore-main-program-for-frozen-scripts-on-MINGW.patch
        0014-Add-missing-library-for-multiprocessing-module.patch
        0015-selectmodule-add-support-for-MINGW.patch
        0016-setup.py-add-libraries-to-fix-compile-of-ctypes-on-M.patch
        0017-Detect-winsock2-and-setup-_socket-module-on-MINGW.patch
        0018-Enable-some-windows-specific-modules.patch
        0019-sysconfig-MINGW-build-extensions-with-GCC.patch
        0020-sysconfig-treat-MINGW-builds-as-POSIX-builds.patch
        0021-Add-support-for-stdcall-without-underscore.patch
        0022-Use-replace-instead-rename-to-avoid-failure-on-windo.patch
        0023-Customize-site-for-MINGW.patch
        0024-add-python-config-sh.patch
        0025-setup.py-add-export_symbols-to-fix-compile-of-ctypes.patch
        0026-mingw-prefer-unix-sep-if-MSYSTEM-environment-variabl.patch
        0027-msys-cygwin-semi-native-build-sysconfig.patch
        0028-sysconfig-mingw-sysconfig-like-posix.patch
        0029-cross-dont-add-multiarch-paths-if-cross-compiling.patch
        0030-mingw-use-backslashes-in-compileall-py.patch
        0031-msys-convert_path-fix-and-root-hack.patch
        0032-mingw-pdcurses_ISPAD.patch
        0033-msys-monkeypatch-os-system-via-sh-exe.patch
        0034-msys-replace-slashes-used-in-io-redirection.patch
        0035-remove_path_max.default.patch
        0036-dont-link-with-gettext.patch
        0037-ctypes-python-dll.patch
        0038-gdbm-module-includes.patch
        0039-use-gnu_printf-in-format.patch
        0040-mingw-fix-ssl-dont-use-enum_certificates.patch
        0041-fix-using-dllhandle-and-winver-mingw.patch
        0042-Add-AMD64-to-sys-config-so-msvccompiler-get_build_ve.patch
        0043-MINGW-link-with-additional-library.patch
        0044-install-msilib.patch
        0045-fix-signal-module-build.patch
        0046-build-build-winconsoleio-and-_testconsole.patch
        0047-expose-sem_unlink.patch
        0048-cygpty-isatty.patch
        0049-disable-broken-gdbm-module.patch
        0050-build-link-win-resource-files-and-build-pythonw.patch
        0051-disable-readline.patch
        0052-fix-isselectable.patch
        0053-_xxsubinterpretersmodule.patch
        0054-configure.ac-fix-inet_pton-check.patch
        0055-set-venv-activate-path-unix.patch
        0056-pass-gen-profile-ldflags.patch
        0057-pkg-config-windows-must-link-ext-with-python-lib.patch
        0058-importlib-bootstrap-path-sep.patch
        0059-pathlib-path-sep.patch
        0060-warnings-fixes.patch
        0061-fix-build-testinternalcapi.patch
        0062-extend-MS_WINDOWS-flag.patch
        0063-clang-arm64.patch
        0064-configure.ac-set-MINGW-stack-reserve.patch
        0065-Don-t-use-os.pathsep-to-find-EOF.patch
        0066-Fix-extension-suffix-for-c-extensions-on-mingw.patch
        0067-Change-the-get_platform-method-in-sysconfig.patch
        0068-distutils-compiler-customize-mingw-cygwin-compilers.patch
        0069-distutils-compiler-enable-new-dtags.patch
        0070-distutils-MINGW-build-extensions-with-GCC.patch
        0071-distutils-use-Mingw32CCompiler-as-default-compiler-f.patch
        0072-distutils-find-import-library.patch
        0073-distutils-avoid-circular-dependency-from-time-module.patch
        0074-distutils-generalization-of-posix-build-in-distutils.patch
        0075-distutils-mingw-sysconfig-like-posix.patch
        0076-distutils-get_versions-fixes.patch
        0077-distutils-install-layout-as-posix.patch
        0078-distutils-msys-convert_path-fix-and-root-hack.patch
        0079-distutils-mingw-build-optimized-ext.patch
        0080-distutils-cygwinccompiler-dont-strip-modules-if-pyde.patch
        0081-distutils-get-compilers-from-env-vars.patch
        0082-distutils-add-windmc-to-cygwinccompiler.patch
        0083-distutils-fix-msvc9-import.patch
        0084-distutils-mingw-add-LIBPL-to-library-dirs.patch
        0085-distutils-Change-the-get_platform-method-in-distutil.patch
        0086-build-Fix-ncursesw-include-lookup.patch
        0087-tests-fix-test_bytes.patch
        0088-time-fix-strftime-not-raising-for-invalid-year-value.patch
        0089-ctypes-find_library-c-should-return-None-with-ucrt.patch
        0090-build-Disable-checks-for-dlopen-dlfcn.patch
        0091-Fix-install-location-of-the-import-library.patch
        0092-Set-MSYS2_ARG_CONV_EXCL-for-the-shared-Python-module.patch
        0093-build-Integrate-venvlauncher-build-installation-into.patch
        0094-configure.ac-set-_WIN32_WINNT-version.patch
        0095-configure.ac-don-t-check-for-clock_-functions.patch
        0096-expanduser-normpath-paths-coming-from-env-vars.patch
        0097-CI-test-the-build-and-add-some-mingw-specific-tests.patch
        0098-Prefer-sysconfig.python_build.patch
        0099-Define-PY3_DLLNAME-to-fix-build.patch
        0100-distutils-remove-checks-for-ancient-gcc-binutils.patch
        0101-distutils-split-CC-env-var-before-passing-to-subproc.patch
        0102-_testconsole.c-Fix-casing-path-sep.patch
        0103-Return-consistent-architecture-markers-for-python-on.patch
        0104-distutils-add-back-gcc_version.patch
        0105-fix-mingw-cross-compiling-in-setup.py.patch
        0106-handle-ncursesw-pkg-config-when-cross-compiling.patch
        0107-mingw_smoketests-fix-_UCRT-condition.patch
        0108-Modify-sys.winver-to-match-upstream.patch
        0109-Change-user-site-packages-path-to-include-the-enviro.patch
        0110-configure-Include-a-header-in-the-check-for-_beginth.patch
        0111-configure.ac-Default-to-without-c-locale-coercion-on.patch
        0112-Fix-failing-tests.patch
        0113-distutils-add-build-root-to-libdirs-when-building-un.patch
        0114-Don-t-change-os.sep-with-an-empty-MSYSTEM-env-var-no.patch
        0115-def-VPATH-when-compiling-Python-sysmodule.c.patch
        0116-Make-_Py_CheckPython3-extern.patch
        0117-link-with-bcrypt.patch
        0118-correctly-find-native-python.patch
        0119-Add-extra-flags-for-_bootstrap_python.patch
        0120-posixmodule-undefine-HAVE_OPENDIR.patch
        0121-getpath.py-add-support-for-mingw.patch
        0122-Don-t-build-_posixsubprocess-on-Windows.patch
        0123-_ssl-link-with-ws2_32.patch
        0124-Fix-building-_socket-module.patch
        0125-Always-normalize-path-in-abspath.patch
        0126-Include-winsock.h-when-checking-for-netdb-function.patch
        0127-include-_multiprocessing-semaphore.c-on-win32.patch
        0128-configure-build-mmap-module-on-win32.patch
        0129-venv-creation-fixes.patch
        0130-move-the-shutdown-function-where-winsock.h-is-includ.patch
        0131-configure.ac-set-BUILDEXEEXT-and-EXEEXT.patch
        0132-configure.ac-fix-building-some-test-modules.patch
        0133-Don-t-convert-sysconfig.get_config_var-VPATH-to-an-a.patch
        0134-Always-convert-to-before-passing-though-pathcch-func.patch
        0135-Build-venvlauncher.exe-from-PC-launcher.c.patch
        0136-getpath.py-fix-dirname.patch
        0137-gh-105821-Use-a-raw-f-string-in-test_httpservers.py-.patch
        0138-getpath-use-normpath-on-all-generated-paths.patch
        0139-pathconfig-normpath-sys.path-0.patch
        0140-smoketests-add-some-tests-for-sys-site-paths.patch
        0141-Search-DLLs-only-on-paths-added-using-add_dll_direct.patch
        0142-Allow-picking-up-include-lib-dirs-from-CFLAGS-LDFLAG.patch
        0143-Build-and-install-libpython3.dll.patch
        0144-setup.py-don-t-prepend-the-system-library-directorie.patch
        0145-tests-skip-a-broken-test.patch
        0146-Port-GetPythonImport-to-mingw.patch
        0147-LoadLibraryExW-make-sure-to-only-use-backslashes-for.patch)

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd "${srcdir}/Python-${pkgver}"

 apply_patch_with_msg 0001-sysconfig-make-_sysconfigdata.py-relocatable.patch \
  0002-build-add-with-nt-threads-and-make-it-default-on-min.patch \
  0003-Define-MS_WINDOWS-and-others-when-compiling-with-MIN.patch \
  0004-configure-add-MACHDEP-and-platform-on-MINGW.patch \
  0005-Add-default-configuration-for-MINGW.patch \
  0006-configure-enable-largefile-support-by-default-for-Mi.patch \
  0007-Add-PC-to-CPPFLAGS-and-to-SRCDIRS-on-Mingw.patch \
  0008-posixmodule.c-Define-necessary-headers-for-compiling.patch \
  0009-Build-winreg-by-default-when-compiling-for-MINGW.patch \
  0010-pyport.h-Add-support-for-MINGW.patch \
  0011-configure-add-options-so-that-shared-build-is-possib.patch \
  0012-Add-dynamic-loading-support-for-MINGW.patch \
  0013-Ignore-main-program-for-frozen-scripts-on-MINGW.patch \
  0014-Add-missing-library-for-multiprocessing-module.patch \
  0015-selectmodule-add-support-for-MINGW.patch \
  0016-setup.py-add-libraries-to-fix-compile-of-ctypes-on-M.patch \
  0017-Detect-winsock2-and-setup-_socket-module-on-MINGW.patch \
  0018-Enable-some-windows-specific-modules.patch \
  0019-sysconfig-MINGW-build-extensions-with-GCC.patch \
  0020-sysconfig-treat-MINGW-builds-as-POSIX-builds.patch \
  0021-Add-support-for-stdcall-without-underscore.patch \
  0022-Use-replace-instead-rename-to-avoid-failure-on-windo.patch \
  0023-Customize-site-for-MINGW.patch \
  0024-add-python-config-sh.patch \
  0025-setup.py-add-export_symbols-to-fix-compile-of-ctypes.patch \
  0026-mingw-prefer-unix-sep-if-MSYSTEM-environment-variabl.patch \
  0027-msys-cygwin-semi-native-build-sysconfig.patch \
  0028-sysconfig-mingw-sysconfig-like-posix.patch \
  0029-cross-dont-add-multiarch-paths-if-cross-compiling.patch \
  0030-mingw-use-backslashes-in-compileall-py.patch \
  0031-msys-convert_path-fix-and-root-hack.patch \
  0032-mingw-pdcurses_ISPAD.patch \
  0033-msys-monkeypatch-os-system-via-sh-exe.patch \
  0034-msys-replace-slashes-used-in-io-redirection.patch \
  0035-remove_path_max.default.patch \
  0036-dont-link-with-gettext.patch \
  0037-ctypes-python-dll.patch \
  0038-gdbm-module-includes.patch \
  0039-use-gnu_printf-in-format.patch \
  0040-mingw-fix-ssl-dont-use-enum_certificates.patch \
  0041-fix-using-dllhandle-and-winver-mingw.patch \
  0042-Add-AMD64-to-sys-config-so-msvccompiler-get_build_ve.patch \
  0043-MINGW-link-with-additional-library.patch \
  0044-install-msilib.patch \
  0045-fix-signal-module-build.patch \
  0046-build-build-winconsoleio-and-_testconsole.patch \
  0047-expose-sem_unlink.patch \
  0048-cygpty-isatty.patch \
  0049-disable-broken-gdbm-module.patch \
  0050-build-link-win-resource-files-and-build-pythonw.patch \
  0051-disable-readline.patch \
  0052-fix-isselectable.patch \
  0053-_xxsubinterpretersmodule.patch \
  0054-configure.ac-fix-inet_pton-check.patch \
  0055-set-venv-activate-path-unix.patch \
  0056-pass-gen-profile-ldflags.patch \
  0057-pkg-config-windows-must-link-ext-with-python-lib.patch \
  0058-importlib-bootstrap-path-sep.patch \
  0059-pathlib-path-sep.patch \
  0060-warnings-fixes.patch \
  0061-fix-build-testinternalcapi.patch \
  0062-extend-MS_WINDOWS-flag.patch \
  0063-clang-arm64.patch \
  0064-configure.ac-set-MINGW-stack-reserve.patch \
  0065-Don-t-use-os.pathsep-to-find-EOF.patch \
  0066-Fix-extension-suffix-for-c-extensions-on-mingw.patch \
  0067-Change-the-get_platform-method-in-sysconfig.patch \
  0068-distutils-compiler-customize-mingw-cygwin-compilers.patch \
  0069-distutils-compiler-enable-new-dtags.patch \
  0070-distutils-MINGW-build-extensions-with-GCC.patch \
  0071-distutils-use-Mingw32CCompiler-as-default-compiler-f.patch \
  0072-distutils-find-import-library.patch \
  0073-distutils-avoid-circular-dependency-from-time-module.patch \
  0074-distutils-generalization-of-posix-build-in-distutils.patch \
  0075-distutils-mingw-sysconfig-like-posix.patch \
  0076-distutils-get_versions-fixes.patch \
  0077-distutils-install-layout-as-posix.patch \
  0078-distutils-msys-convert_path-fix-and-root-hack.patch \
  0079-distutils-mingw-build-optimized-ext.patch \
  0080-distutils-cygwinccompiler-dont-strip-modules-if-pyde.patch \
  0081-distutils-get-compilers-from-env-vars.patch \
  0082-distutils-add-windmc-to-cygwinccompiler.patch \
  0083-distutils-fix-msvc9-import.patch \
  0084-distutils-mingw-add-LIBPL-to-library-dirs.patch \
  0085-distutils-Change-the-get_platform-method-in-distutil.patch \
  0086-build-Fix-ncursesw-include-lookup.patch \
  0087-tests-fix-test_bytes.patch \
  0088-time-fix-strftime-not-raising-for-invalid-year-value.patch \
  0089-ctypes-find_library-c-should-return-None-with-ucrt.patch \
  0090-build-Disable-checks-for-dlopen-dlfcn.patch \
  0091-Fix-install-location-of-the-import-library.patch \
  0092-Set-MSYS2_ARG_CONV_EXCL-for-the-shared-Python-module.patch \
  0093-build-Integrate-venvlauncher-build-installation-into.patch \
  0094-configure.ac-set-_WIN32_WINNT-version.patch \
  0095-configure.ac-don-t-check-for-clock_-functions.patch \
  0096-expanduser-normpath-paths-coming-from-env-vars.patch \
  0097-CI-test-the-build-and-add-some-mingw-specific-tests.patch \
  0098-Prefer-sysconfig.python_build.patch \
  0099-Define-PY3_DLLNAME-to-fix-build.patch \
  0100-distutils-remove-checks-for-ancient-gcc-binutils.patch \
  0101-distutils-split-CC-env-var-before-passing-to-subproc.patch \
  0102-_testconsole.c-Fix-casing-path-sep.patch \
  0103-Return-consistent-architecture-markers-for-python-on.patch \
  0104-distutils-add-back-gcc_version.patch \
  0105-fix-mingw-cross-compiling-in-setup.py.patch \
  0106-handle-ncursesw-pkg-config-when-cross-compiling.patch \
  0107-mingw_smoketests-fix-_UCRT-condition.patch \
  0108-Modify-sys.winver-to-match-upstream.patch \
  0109-Change-user-site-packages-path-to-include-the-enviro.patch \
  0110-configure-Include-a-header-in-the-check-for-_beginth.patch \
  0111-configure.ac-Default-to-without-c-locale-coercion-on.patch \
  0112-Fix-failing-tests.patch \
  0113-distutils-add-build-root-to-libdirs-when-building-un.patch \
  0114-Don-t-change-os.sep-with-an-empty-MSYSTEM-env-var-no.patch \
  0115-def-VPATH-when-compiling-Python-sysmodule.c.patch \
  0116-Make-_Py_CheckPython3-extern.patch \
  0117-link-with-bcrypt.patch \
  0118-correctly-find-native-python.patch \
  0119-Add-extra-flags-for-_bootstrap_python.patch \
  0120-posixmodule-undefine-HAVE_OPENDIR.patch \
  0121-getpath.py-add-support-for-mingw.patch \
  0122-Don-t-build-_posixsubprocess-on-Windows.patch \
  0123-_ssl-link-with-ws2_32.patch \
  0124-Fix-building-_socket-module.patch \
  0125-Always-normalize-path-in-abspath.patch \
  0126-Include-winsock.h-when-checking-for-netdb-function.patch \
  0127-include-_multiprocessing-semaphore.c-on-win32.patch \
  0128-configure-build-mmap-module-on-win32.patch \
  0129-venv-creation-fixes.patch \
  0130-move-the-shutdown-function-where-winsock.h-is-includ.patch \
  0131-configure.ac-set-BUILDEXEEXT-and-EXEEXT.patch \
  0132-configure.ac-fix-building-some-test-modules.patch \
  0133-Don-t-convert-sysconfig.get_config_var-VPATH-to-an-a.patch \
  0134-Always-convert-to-before-passing-though-pathcch-func.patch \
  0135-Build-venvlauncher.exe-from-PC-launcher.c.patch \
  0136-getpath.py-fix-dirname.patch \
  0137-gh-105821-Use-a-raw-f-string-in-test_httpservers.py-.patch \
  0138-getpath-use-normpath-on-all-generated-paths.patch \
  0139-pathconfig-normpath-sys.path-0.patch \
  0140-smoketests-add-some-tests-for-sys-site-paths.patch \
  0141-Search-DLLs-only-on-paths-added-using-add_dll_direct.patch \
  0142-Allow-picking-up-include-lib-dirs-from-CFLAGS-LDFLAG.patch \
  0143-Build-and-install-libpython3.dll.patch \
  0144-setup.py-don-t-prepend-the-system-library-directorie.patch \
  0145-tests-skip-a-broken-test.patch \
  0146-Port-GetPythonImport-to-mingw.patch \
  0147-LoadLibraryExW-make-sure-to-only-use-backslashes-for.patch
 
  autoreconf -vfi
}

build() {
  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("--enable-optimizations")
    # Upstream defaults to -O3, so we can do too
    CFLAGS+=" -O3"
    # FIXME: https://github.com/msys2-contrib/cpython-mingw/issues/10
    # _extra_config+=("--with-lto")
  else
    CFLAGS+=" -O0 -ggdb"
    CXXFLAGS+=" -O0 -ggdb"
    _extra_config+=("--with-pydebug")
  fi

  case "${CARCH}" in
    i686)
      LDFLAGS+=" -Wl,--large-address-aware"
    ;;
  esac

  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../Python-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --host=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --enable-shared \
    --with-system-expat \
    --with-system-ffi \
    --with-system-libmpdec \
    --without-ensurepip \
    --enable-loadable-sqlite-extensions \
    --with-tzpath=${MINGW_PREFIX}/share/zoneinfo \
    "${_extra_config[@]}"

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  # Some basic tests to ensure nothing major or MSYS2 specific features are broken
  ./python.exe "../Python-${pkgver}/mingw_smoketests.py"
  MSYSTEM= ./python.exe "../Python-${pkgver}/mingw_smoketests.py"
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make -j1 install DESTDIR="${pkgdir}"

  # gdb pretty printers for debugging Python itself; to use:
  # python
  # sys.path.append('C:/msys64/mingw64/share/gdb/python3')
  # import python_gdb
  # reload(python_gdb)
  # end
  if [[ "${_primary_python}" == "yes" ]]; then
    [[ -d "${pkgdir}${MINGW_PREFIX}"/share/gdb/python3/ ]] || mkdir -p "${pkgdir}${MINGW_PREFIX}"/share/gdb/python3/
    cp -f python.exe-gdb.py "${pkgdir}${MINGW_PREFIX}"/share/gdb/python3/python_gdb.py
  fi

  # some useful "stuff"
  install -dm755 "${pkgdir}${MINGW_PREFIX}"/lib/python${_pybasever}/Tools/{i18n,scripts}
  install -m755 "${srcdir}/Python-${pkgver}"/Tools/i18n/{msgfmt,pygettext}.py "${pkgdir}${MINGW_PREFIX}"/lib/python${_pybasever}/Tools/i18n/
  install -m755 "${srcdir}/Python-${pkgver}"/Tools/scripts/{README,*py} "${pkgdir}${MINGW_PREFIX}"/lib/python${_pybasever}/Tools/scripts/

  # fixup shebangs
  for fscripts in 2to3 2to3-${_pybasever} idle3 idle${_pybasever} pydoc3 pydoc${_pybasever}; do
    sed -e '1 { s|^#!.*$|#!/usr/bin/env python'"${_pybasever}"'.exe| }' -i "${pkgdir}${MINGW_PREFIX}"/bin/${fscripts}
  done

  # default aliases for all scripts/binaries
  if [[ "${_primary_python}" == "yes" ]]; then
    # Default names are aliases for Python now
    cp "${pkgdir}${MINGW_PREFIX}"/bin/python3.exe "${pkgdir}${MINGW_PREFIX}"/bin/python.exe
    cp "${pkgdir}${MINGW_PREFIX}"/bin/python3w.exe "${pkgdir}${MINGW_PREFIX}"/bin/pythonw.exe
    cp "${pkgdir}${MINGW_PREFIX}"/bin/python3-config "${pkgdir}${MINGW_PREFIX}"/bin/python-config
    cp "${pkgdir}${MINGW_PREFIX}"/bin/idle3 "${pkgdir}${MINGW_PREFIX}"/bin/idle
    cp "${pkgdir}${MINGW_PREFIX}"/bin/pydoc3 "${pkgdir}${MINGW_PREFIX}"/bin/pydoc
  fi

  # delete anything that could conflict with the primary Python
  if [[ "${_primary_python}" != "yes" ]]; then
    rm "${pkgdir}${MINGW_PREFIX}"/bin/python3.exe
    rm "${pkgdir}${MINGW_PREFIX}"/bin/python3w.exe
    rm "${pkgdir}${MINGW_PREFIX}"/bin/python3-config
    rm "${pkgdir}${MINGW_PREFIX}"/bin/idle3
    rm "${pkgdir}${MINGW_PREFIX}"/bin/pydoc3
    rm "${pkgdir}${MINGW_PREFIX}"/bin/2to3
    rm "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/python3-embed.pc
    rm "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/python3.pc
    rm "${pkgdir}${MINGW_PREFIX}"/share/man/man1/python3.1
  fi
}

sha256sums=('85cd12e9cf1d6d5a45f17f7afe1cebe7ee628d3282281c492e86adf636defa3f'
            '4a40ee813a68cbc083b3d7ef2ae624ef6fc8ca145f6d3af13f3b1c5097351fb0'
            'd6e3d59b1a2495e072cbeb5a69154f5fa2d0a66f6eeb3732c984fed7de6c3b08'
            '189abee18210b9d1ba70dd8e9b41ba59f2e4917bdc29f20ae5422ca704a9b44c'
            '603a8797390ab6b4ba9d98d6b515540917a6f91cd7295fc72d641929ff1bdbf4'
            '5c2e0b6b7ac0252b8032483f8018e60d5c6ed658ee8f69cd88916f640d148679'
            'ca7c6d8a031b2432e36e7c9ae2918d010dfdfccf25cd110a033ecccb153a955f'
            '89feaf0e1b30140b7e5d33a76130b16f0360aef082d0099ce85186c0d2b67d8a'
            'b49e84722a97e562c8c2f8f21d1a0271b3ef69c045e20461aa1a6d6f29b2c502'
            '15d3a38b4a68d863dcc737bd84efba8a9e3d28b3b9907204a34f10c811406975'
            '86ee3ace5dc6745e9fc442befa12c01e43889994428d9b49057f358854211d3a'
            '5650d6486aad145b900eff5d9dea27cf3e504e401fc5de886b289e3ab8aac26c'
            '9868715ed72a2dcbaabd0134f0913457498441b534bb3345c548e851e779b988'
            '7a1450ffb009761807628034920d5fd7018e14ba7d3a233ce604abee641e8cd1'
            'f28e35f4ab431a1c979d8c079df6e36592faa9d4549b7e0484a5b17eac88a394'
            'da963f32be94dc944e564bc9252d407757a94c5e423bfbd9d172f8a8dff4b69b'
            '368e1a7a908b33a0fbde628fdd771521562603bbbc5d5f3e57fe560be08fe60a'
            'b029c2a55106000b0b172fcafaa570d8357efdbd917e094c636a566e5d97196f'
            '2fb5469c90bd79c9e2f48782c54bee4010806d282185fe6f7fee092262ace673'
            'de033dc4a7754f4986bc67f898f4a925fbbc9f612a751cfaf285103210982ee8'
            'e5c41b05487be5cb88c09b80262fb381f9ea16d85129cfd71a590a25e704dc11'
            '6c33b5943451122c73d629366e06c433ff4c2e4cdf10d20287c1db4494e97150'
            '68fd29d3dd13df204504a697c65c9a81c8e3c36b4a5b956d422bde5e227f318a'
            'a967b1740ef0c4ccaa20ca6262c32d51902e0d100f55db069a0a5b39a9d17fb5'
            'db83b571d3d001309d4eb02866670109849dcd97d23d9c0b4aee3c312fd51ca9'
            'cf6c802c6155882d6edcaf343863addc91d949fcbeef1c005fd208261893ad36'
            '88eceea271e0001e08340b5995dc5d51afb6efec93bdf6b5819ec518db9e88a5'
            '28247e6afe28c170156c984d2439af1b3f5e72063a12b8132153806c7fb47100'
            '21a96a04662684cdfab9804ad22064ae36b1f253e5241f74fd47e5d85d9cec85'
            'eabfe06001166205002019d2f5e83f025a4f2e12e49e1f2a9e879770364b9c0d'
            '76ac0d7c5aca10075cc31a0c8f73f179278929b19a5efd4770b9f80b1923028a'
            '68dd311a5ecb8b500448100239fb0e5dd6e76821654746da1093737544e4c726'
            '7c75f0e7764292c718723e2307d2694545c9b373340e440adfd90083ea4b5d7f'
            '49a8732840ee64b8f40cec26e0dd1e68834f66d937d85639f364e9a2f33d0335'
            'd5f7d9517a744985ea8ba3eae3b452562b3959858b5b8d0b928f3a7248c0846b'
            'c661968d33ba7be4d8ff5f427f3beb82d17fe34d7a7802b2bd1f75c99d89b2c8'
            'fc6f67d274cc025798d5754508b660d3af1dd1cf3af09fceb2f9efbca9f3e221'
            'ba0e10738f6e1f54b4e3f99732babb3925c7f319bc35f02ffb994df85823ea31'
            'aa073aed227b8e9fba185cca960a04718d3448e28c9a0faf09c7108d43b5be5a'
            '550162769891fb49477206a0bc72c4dcf7d25b5b8fc36acdbbe967c74a0e00fa'
            '39853b8c494ee9bede61ca2451c648fbf63992cf2540fd52a0ad707fb543a173'
            'cdde314bb0cd8dbef4b40b3a06ddce9ce89ed4c595bb692e36882c192d312dcc'
            'd01c26fbb4984cf1280b725375e7049d9d187c2db7df11b03354f653f4c4aa39'
            '9ed2f75ad681a544fc80735cb6c0780fb1de523142c8bb108d667eaa8540601d'
            '69f26e950c99456b0513d2780d03f6bbf7b91661e8499a8bdcb6aad978446471'
            'e064ef166a6a60bb40ccafc505062c2f88dc6b2308eb275f94cbf9e9e951b987'
            '4685434738a67e4e1ea33766fa77ff49b2c50e6f9394c3f000c4d0777671866c'
            '0dd14211734558980af978ada8c95de99c8c0d2ea04c0737f4b78d4943c3c01e'
            '02bd01e5b0ce645e163f3301f1a2adbb37c0fd33be9820703a0934e6a5ba2118'
            '49d35afeb89d3aa2dd1746f0f53e1018074a54f44dac28b8842b745b5ec42efe'
            'ba638f9d7578aa6078794c8cafb5fc612060df4ce9955ade8d574f721308a6ed'
            'f42b83ac99b01ff0d033f29be5616396a2269370d2d2020fd009ac8355aa51f7'
            '84aabf117371e0774112d0c026fc414fcb7e69294802f90881e46866ebb1785c'
            'f4cf441878e1a477b353f54dc4bacfa14de4de1057abb6601243813ad0e49c1a'
            '871bd009436eb0786dbf3017e540e59f12f1560076aac8248c30224b01938243'
            '3efc10df4ef60dca9a8cc2d55f50d9b66abfa123fdbfa739accb527cb4ddf351'
            '8ef25666be6cfd39cac861e14b62f702f8f5c5a0162ebf271cdb2718db0a3660'
            'e466fffcd146695236e23b506dce1bd0591db32d75b030a334304e6c29258006'
            'f4fc7dcf6cfd8fb33d919a28cf4034e5ada7b8ee3a6b228d7824ffef83451eb9'
            'b03937aaf49c773722ad9e9f038096c9d6460dee86aa53c9a8217d67d88034a0'
            '208bb1fdc437904708ea070e332d0b24e62522454e2dac031c2783596951d8a2'
            '698b0ecd96e0e385fa96c15a6306b5fe5e2b2c0f413f9c18061e045a17cf9ab4'
            '7d26fe41c4e42cf923cf1065d2503ed2ba4b931ce1d50498477a80362ffc2d83'
            '85eb804fefc3bfa24e019b80a2fd414b69dacdd275daa9d3c6d0654639f14604'
            '47836511e94abdecfa471dc8d0af72537c3ced4dafae579c133387bc30e0cd0c'
            'fc05e6d57d5cac737176ca2a27886a76b2611ce97397ac43b5b4e2fe81ef22a3'
            '178216f3251dde9da502992802ec82d597cd80cc2923fbdacc036fee95a15742'
            '45f80bfcaab349d2220e0818fb6ea623270a823723b47e3994c2933c95145f62'
            '2658af3e5df724613497832ac25ef29e41097ad98029c91468bfa0c3b4c39ce2'
            '858941b799ba5b131271157ff0c2b2749d7a4df779515cffad1427c8dc036507'
            'af36bb2eec0aaebd7fc70fe107f68e84a0f9ee27c0057b6677b7922b193e1f23'
            '82250b5d6589ebf8191f7455701101e93fe71acf6efd5b16be8058232806ff6a'
            '098f707e28242a7864edf945a4782de2815de3392e1a0f9142f7dad78c769408'
            'dfbabca1ef4f5a85dce8c47adff05001920f6d4a6b3278a11c054b733e79b6bf'
            '6c16857071899137365c97a6024a75a8026b0b7b106a3956184df0425e909eef'
            '13b9bec4e6d5e7ddda6c836b90b1610954235d2e54cbf522f47dfb4ad6e47ac9'
            'fda0644a93a84e62ccfb7dcbaa27c41d0082f25ce73257608aff56c0d89d35a9'
            'd65ddc677e959aa3d4c055f5b414a8a0e327dcf349eebb7bc58f8f2e7b13b505'
            'f570cee22eb8425cc9a235d2bf9644d42bb4dd9dbbc98f085a07b3ee3dd6db23'
            '6a5bd7efd952b4bc81ec54532f9718ba91647724d90c1edaa479f27af443dc98'
            '4f803a2d1b54e20137c47c98452f560f1cd04b876148a8b3f6af25b29c25ad0c'
            '73f22b079e557a3c31d16360a21ab4aa8905539a3f08547ea0fb4478eee7b60e'
            'd841eb9520a0b7ebacfb5373f9de11daa2c6733b6272824901ebc272ebea49f6'
            'bbc1313298a3f6a1d7b92abafd650f083b990b3125fe79286644e1d62206552e'
            '9f666167a7f695a57b17c7baac884dbe5a497c126cdb08b2c6185e4734180daf'
            '0407b9ba5275686b0b257f66049cd83b930d04a969b495c2f767a7582cde82ff'
            'fc8ddd4d6b695e755b3d0cd5f2dc2f552053ec5e7597235b8e16fb0af461eb4c'
            'ed2a2106cb56f6bc311b5b951aa84f9de84d777a5bda27cfc0621a43080b6678'
            '67ec7e8f26313e292adafddc250155bfef3c443ab1adfd56e04b6ab4a46bcb87'
            '64927764c276028abe53465523cbd5a42432a579988a40a22cb42d242e23eb3c'
            'f73c60babe3b4f1be38198d7a510369e772e9a4a6a01ddc814ea047be5ad32c5'
            '69322fffcdd27d253537f34f2cbfcf04c9673c11f652332ac2c32a07c540fb7f'
            'b45aad644db1de0fb5234583a6ad16da2589b566804fc3a6296b878aa6e11ec7'
            '54c0a68855730137660cd9076caa8afd1d2acba5a846d5e745201d5ccc35bf84'
            '787e33290877c2373ae9e999c3ae8973e40d36877be316bbaec6a581920f56f8'
            '4a8c52191fcd8f39e4e2f29ddad638d3980855a091ed2e379403a78e0e392933'
            '4424a57742ebedbe83dc3937d53a90bbb6b5318c69068721a1837d5aa26ca889'
            '368e3e8740bc58c037671e16deb4a1fc98d517d2745a2a3d2183b98a5153f7fe'
            'ff27d4efec23581efcb89c21b1f48ef51ae34c6dc49b41bd1144cdba7e44640f'
            '02e11bfc6151dd42525e809c6ee4987a5286e37f258b4c5183193c21e9edd93c'
            'c6694eee6e9ff0c97c61f656a9a486faaa3a10504210d081c6e7782a8edb7697'
            '67d34fb28f454ccd6781ca4903797490435736379f80560a171d425a9476b8eb'
            '3d47a8b93c508b65988871daa82d1220ed14efed96de7f63cba20d14b87d7380'
            '2d52bf5fea5fa7a17171c99a6acc626c23c548e57c5a5b98cbfef886c825eb2f'
            'e32d0ec699919d5656a43b8910e216617528515b3b308eab1b8155700f6d60fa'
            'dda17e7579a09192af21873099f71354d45268d8148321cd5ecd5aa99a382ab2'
            '8d57e6aa948b9a3e2e5ae9465afa65a7adf9ae02973232befdc3d16225209288'
            '713514562f236a92048084a2c2dcde780400b818eda1055a429376f8e98757d8'
            'de3fb092a3da6de2e279a829df9bdbd738a31eb7d75cc79c49f9fe0bdd81d28e'
            '7dc348b75411d28f34b9c14ed5dbf32e5b74131c6fe0f01cae77c86644522e36'
            '0e19f579a20dd234e1dc30485a7d4669836d1d1f069d13b8922189489c61cb27'
            '416cd4104f9e3baa798a876a082a4c9d33d73d57cdbbeb200b0dfbda73f0323e'
            '4dcadf30fcd42a13091c87fc5a5fbb524bab64210bfeb17147133b56f14f51be'
            'e09f7847210d44a8384e59ef7c975f36e1ca444800c6d4c3cd981b861076fb2b'
            '64d1ff92a3ffd1bc7c70a66d5d99bbadedb2a076a0868802e2c4ed051234f774'
            'ba9f982462915964d2cd06bea3719efd3836587401f38b4264793e1d30ddab32'
            'e60648d47facb965e42c7746792378b1278b029fec2afeb222323282a57211ea'
            'ad7c6a67729fe885bb441f268f483bd7b9aceb1a8cd49284632473d959256a31'
            'ca69cc66e7452eaa2b46f888c02538dafaf6ab3ec143de5f3e56aafb4c627439'
            '922faf6679d30c6fc3a123bb78ee6959ac1fa7acd07037710d5104982625a275'
            '4d0103c4e704867e424639e338f3d938572d831b8b8b94bdb21e1ed75071e5ef'
            '3b24f0b1f729f35d1f762eaa40f40ba985124350982d1ed1661be9a5fb5166e1'
            '5721182ca05bfb82f0bdfd8470a76c3000b2783cae7c0de8c2cbe09d79284821'
            'b7cf1c0648716685ac3a38c0e15be4d1682c9ed39742098dcb529aff3bd3cb44'
            'b693ba21f1c30ae4fa94f1bc274984455f8e968b5b1ce813bc915e11e8c14a41'
            '106243f6174941d8bf7250ae594d52aeefacd357599d923a7293bdc954cc1371'
            '5bc983ff39a5062d381b08bcb8619798a71cb3afd221de0fe830726ddb3d0928'
            '8e2ccd543862f7a2de0ed55ed7931502c738e8ca4c62a50b0d029f4ad04c6f48'
            'f8060a09ee3e17b6b25a382f1f709053d4531a4875bad859a3e90d83be066bbc'
            '4db785442c6139721475affcbb49ca5fcd219103131392d38da9caa830d96a9c'
            'f19524c8026c736a1d159fcd14894b002a5ae1286eaae38801104df705de2582'
            '39b9a61d5442d275e1f6c3fdf2ebffc82a6207302c54b8b67a4c3f339dbae45d'
            'c2949d1c24dd9df84f99eaf195e2f1b30921b2d89b1c7a18831d444916b8156c'
            '5aae8b41a0e35960fe8c2a289347c56871e44e58e9e49858039c9c68578a1111'
            '2b0b37d65dde2dcf79af101fa0e4b1e685b6c428c2f0bff5729edb9402bf3eb3'
            '2945a9a65d84bc64cb93b51395e15b50dae9cc7d1332b17c31967997d56ecb5e'
            'a769b00821d82fd9fdff8d148db4129d010652fe9f58bfd0b906d7cb9f0c271d'
            'd7f7afbe5476348d286fbd4e2614f4bb8285282eab48ed9650936ca9d51cc6f2'
            'ce383107b26ddf5a94c688615032bbf9521422e71586c6c04c0c53fc66d30ce5'
            '5d95995d79f4329b1a16e635bb9ff2a2a2c8cae636cc07369e3b7dd2bbbd9896'
            '6c41a77a2399ca13ab512d7a62e43459807d9ba91627fad70eb3827823490581'
            '71ea2425b9ba0b29a8ca7cc12a26787ce4775a3effaa49070da103892274cf5f'
            '69cf576d5083088b1239b3bcbe30d18e6cb85e1dab8738f8b04007ef35fd40bd'
            '8df3f5bee7856ee12ea705d6d31358f5ee5ff2c8eb99ab1aad9101afe92893b9'
            '6e0d29ee44c5d5ab8605a980c7cee246acf5ccce638e6a7cee4c4e7a8ec865cd'
            '3b6bf12600203d45ff9b0ecde0bb9959c4fde923c9609e4c1e18b6d7877e3f1b'
            'd9a54181024f0b538d8903bdf772a0dd754811aab339e6f553c47e1198ab04cc'
            '71fd408d8bb8ca40584f287adea583032d1b7150f011abe2165c44d468428f0f')
